#include "Thread.hpp"
#include <string.h>

using namespace ThreadModule;

int getDouble(int val)
{
    return val * 2;
}
void test1()
{
    int x = 100;
    
    Thread<int(int), int> th(getDouble, std::move(x));

    int* result = (int*)th.Join();
    std::cout << "result = " << *result << std::endl;
}


int getSum(int a, int b)
{
    return a+b;
}
void test2()
{
    int a = 100;
    int b = 200;

    Thread<int(int, int), int, int> th(getSum, std::move(a), std::move(b));

    int* result = (int*)th.Join();
    std::cout << "result = " << *result << std::endl;
}


int* createArray(int n)
{
    int* arr = new int[n];
    for(int i = 0; i < n; i++)
    {
        arr[i] = i;
    }
    return arr;
}
void test3()
{
    int size = 100;

    Thread<int*(int), int> th(createArray, std::move(size));
    int** arr = (int**)th.Join();

    for(int i = 0; i < 20; i++)
    {
        std::cout << (*arr)[i] << " ";
    }
    std::cout << std::endl;

    delete[] *arr;
}

#include <vector>
#include <algorithm>
std::vector<int> getSortVector(std::vector<int> v)
{
    sort(v.begin(), v.end());
    return v;
}
void test4()
{
    std::vector<int> v {1,5,7,-2,7,3,9,6,-4,-1,10,-3,4};
    Thread<std::vector<int>(std::vector<int>), std::vector<int>> th(getSortVector, std::move(v));

    std::vector<int> result = *((std::vector<int>*)th.Join());
    for(auto e: result)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}

int main()
{
    //test1();
    //test2();
    //test3();
    test4();

    return 0;
}